<?php
/**
 * @package		Joomla.Site
 * @subpackage	com_content
 * @copyright	Copyright (C) 2005 - 2012 Open Source Matters, Inc. All rights reserved.
 * @license		GNU General Public License version 2 or later; see LICENSE.txt
 */

// no direct access
defined('_JEXEC') or die;

JHtml::addIncludePath(JPATH_COMPONENT.'/helpers');

?>

<div class="category_home">
	
	<ul class="category_item">
		<?php foreach ($this->items as $category): ?>
		<?php if ($category->articles): ?>
		<li class="category_level1">
			<h2 class="item-title"><a href="<?php echo JRoute::_(ContentHelperRoute::getCategoryRoute($category->id));?>">
				<?php echo $this->escape($category->title); ?></a>
			</h2>
			
			<?php if ($category->articles):
			
			//get first article 
			$firstArticle = $category->articles[0];
			
			$firstArticleImage = json_decode($firstArticle->images);
			
			//set slug
			$firstArticle->slug = $firstArticle->alias ? ($firstArticle->id . ':' . $firstArticle->alias) : $firstArticle->id;
			?>
			<div class="category_content_item">
                <div class="category_content">
                    <?php if ($firstArticleImage->image_intro): ?>
                    <img src="<?php echo $firstArticleImage->image_intro; ?>" align="left"/>
                    <?php endif; ?>
                    <h3 class="list-title">
                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($firstArticle->slug, $firstArticle->catid)); ?>">
                            <?php echo $this->escape($firstArticle->title); ?>
                        </a>
                    </h3>
                    
                    <?php echo JHtml::_('string.truncate', strip_tags($firstArticle->introtext), 200); ?>
                </div>
                
                
                <ul class="category_list">
                    <?php foreach ($category->articles as $key => $article): ?>
                    <?php 
                            if ($key == 0) continue; 
                            
                            $article->slug = $article->alias ? ($article->id . ':' . $article->alias) : $article->id;
                    ?>
                
                    <li>
                        <a href="<?php echo JRoute::_(ContentHelperRoute::getArticleRoute($article->slug, $article->catid)); ?>">
                            <?php echo $this->escape($article->title); ?>
                        </a>
                    </li>
                
                    <?php endforeach; ?>
                </ul>
                <?php endif; ?>
            </div>
		</li>
		<?php endif; ?>
		<?php endforeach; ?>
	</ul>
		
</div>